import hashlib, hmac, base64

class XoSigner(object):
    def __init__(self, access_key, secret_key):
        self.access_key = access_key
        self.secret_key = secret_key

    def _hmac_sha1_base64(self, key, text):
        key_bytes = bytes(key, encoding='utf-8')
        text_bytes = bytes(text, encoding='utf-8')
        hash_msg = hmac.new(key_bytes, text_bytes, hashlib.sha1).digest()
        return str(base64.b64encode(hash_msg), encoding='utf-8')

    def _get_string_to_sign(self, http_verb, content_type, date, uri):
        return http_verb + "\n\n" + content_type + "\n" + date + "\n" + uri

    def authorization_signature(self, date, http_verb, uri):
        string_to_sign = self._get_string_to_sign(http_verb, "", date, uri)
        signature = self._hmac_sha1_base64(self.secret_key, string_to_sign)

        return 'AWS {}:{}'.format(self.access_key, signature)
